<?php
if (!isset ($_GET["id"]) || !is_numeric($_GET["id"]) ){
    throw new Exception("Erro na passagem de parametros");
}

include_once $app."dao/dao_usuario.php";

$dao_usuario = new dao_usuario();
$model_usuario = $dao_usuario->selectByCLI_ID($_GET["id"]);

?>

<script>

$(document).ready(function(){
    desabilitaBotao($("input:submit",document.forms));
    $("input", document.forms).prop("disabled", true);
    $("select", document.forms[2]).prop("disabled", true);
});

//$("#img_cliente").ready(function(){
//    $("#img_cliente").attr("src", "./imagens/clientes/<?php //echo $_GET["id"] ?>.jpg?"+(new Date()).getTime());
//});

function valida(){
        form = document.usuario;
        senha = form.elements["usuario[USU_SENHA]"];
        senha_verificacao = form.elements["senha_verificacao"];
        
        if (senha.value.length < 6){
            alert("A senha deve ter no ménimo 6 caracteres");
            return false;
        }else if (senha.value != senha_verificacao.value){
            alert("As senhas não coincidem");
            return false;
        }
        show_loading_screen();
        return true;
}

function configura_form(component){
    desabilitaBotao($("input:submit",document.forms));
    $("input", document.forms).prop("disabled", true);
    $("select", document.forms[2]).prop("disabled", true);
    switch (component) {
            case document.getElementsByName("action")[0]:
                $("input", document.forms[0]).prop("disabled", false);
                habilitaBotao($("input:submit", document.forms[0]));
                break;
            case document.getElementsByName("action")[1]:
                $("input", document.forms[1]).prop("disabled", false);
                habilitaBotao($("input:submit", document.forms[1]));
                break;
            case document.getElementsByName("action")[2]:
                $("input", document.forms[2]).prop("disabled", false);
                habilitaBotao($("input:submit", document.forms[2]));
                $("select", document.forms[2]).prop("disabled", false);
                break;
            default:
                break;
        }

}

</script>
<div class="div_conteudo">
<span class="titulo_conteudo">Altera&ccedil;&atilde;es do Usu&aacute;rio '<?php echo $model_usuario->getUSU_NOME() ?>'</span>
<div class="corpo_conteudo">
    <fieldset>
        <legend><input type="radio" name="action" id="action1" onchange="configura_form(this);"/><label for="action1">Alterar Senha</label></legend>
        <form class="formularios" style="color: #006600; font-weight: bold;" name="usuario" action="./action.php?action=usuario_altera_senha" onsubmit="return valida();" method="post">
        <br/>
        <input type="hidden" name="CLI_ID" value="<?php echo $_GET["id"] ?>" />
        <input type="hidden" name="usuario[USU_ID]" value='<?php echo $model_usuario->USU_ID ?>'/>
        <table>
            <tr><td>Usu&aacute;rio:*</td><td><input type="text" name="nome" readonly="readonly" value='<?php echo $model_usuario->USU_NOME ?>'/></td></tr>
            <tr><td>Senha:*</td><td><input type="password" name="usuario[USU_SENHA]" maxlength="30"/></td></tr>
            <tr><td>Repetir Senha:</td><td><input type="password" name="senha_verificacao" maxlength="30"/></td></tr>    
        </table>
        <small>* A senha do usu&aacute;rio deve ter no m&iacute;nimo 6 e no m&aacute;ximo 30 caracteres</small><br/><br/>
        <br/>
        <input type="submit" value="Salvar"/>
        </form>
    </fieldset>
</div>
<div class="corpo_conteudo">
    <fieldset>
        <legend><input type="radio" name="action" id="action2" onchange="configura_form(this);"/><label for="action2">Mudar Logomarca</label></legend>
        <table>
            <tr>
                <td>
                    <form class="formularios" name="logo" enctype="multipart/form-data" action="./action.php?action=usuario_altera_logo" method="post" onsubmit="show_loading_screen();">
                        <br/>
                        <input type="hidden" name="CLI_ID" value="<?php echo $_GET["id"] ?>" />
                        <input type="hidden" name="MAX_FILE_SIZE" value="4194304" />
                        Arquivo:<br/>
                        <input type="file" name="arquivo"/><br/>
                        <small>Tamanho ideal da imagem &eacute; de 100x75 pixels</small><br/><br/><br/>
                        <input type="submit" value="Salvar"/>
                    </form>
                </td>
                <td>
                    <img style="border: 1px solid #ccc" src="imagens/clientes/cliente_100x75.php?id=<?php echo $_GET["id"] ?>" id="img_cliente" width="100" height="75" alt="LOGO"/>
                </td>
            </tr>
        </table>
    </fieldset>
</div>
<div class="corpo_conteudo">
    <fieldset>
        <legend><input type="radio" name="action" id="action3" onchange="configura_form(this);"/><label for="action3">Alterar status</label></legend>
        <form class="formularios" style="color: #006600; font-weight: bold; " id="form_usuario" name="status" action="./action.php?action=usuario_altera_status" method="post" onsubmit="show_loading_screen();">
            <br/>
            <input type="hidden" name="CLI_ID" value="<?php echo $_GET["id"] ?>" />
            <input type="hidden" name="usuario[USU_ID]" value='<?php echo $model_usuario->USU_ID ?>'/>
            Status: <?php 
            if($model_usuario->getUSU_STATUS() == 'A'){
                echo "Ativo";
            }else if($model_usuario->getUSU_STATUS() == 'I'){
                echo "Inativo - Aguardando confirmar&ccedil;&atilde;o do pagamento";
            }else if($model_usuario->getUSU_STATUS() == 'B'){
                echo "Bloqueado";
            }else if($model_usuario->getUSU_STATUS() == 'C'){
                echo "Cancelado";
            }else if($model_usuario->getUSU_STATUS() == 'P'){
                echo "Pendente - Aguardando confirmar&ccedil;&atilde;o do e-mail";
            }
            $model_usuario->getUSU_STATUS() ?><br/>
            <select name="usuario[USU_STATUS]">
                <option value="">Selecione</option>
                <option value="A">Ativo</option>
                <option value="B">Bloqueado</option>
                <option value="C">Cancelado</option>
                <option value="I">Inativo - Aguardando confirmar&ccedil;&atilde;o do pagamento</option>
                <option value="P">Pendente - Aguardando confirmar&ccedil;&atilde;o do e-mail</option>
            </select><br/><br/>
            <input type="submit" value="Salvar"/>
        </form>
    </fieldset>
</div>
</div>